<?php

namespace app\admin\model\mox\play;

use think\Model;


class Info extends Model
{





    // 表名
    protected $name = 'mox_play_info';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'create_time_text',
        'update_time_text'
    ];


    protected $toggleFields = ['is_perform', 'is_represent'];



    public function getCreateTimeTextAttr($value, $data)
    {
        $value = $value ?: ($data['create_time'] ?? '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getUpdateTimeTextAttr($value, $data)
    {
        $value = $value ?: ($data['update_time'] ?? '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    protected function setCreateTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setUpdateTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    public function user()
    {
        return $this->belongsTo('app\admin\model\User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
    public function type()
    {
        return $this->belongsTo('app\admin\model\mox\play\Type', 'type_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
    public function story()
    {
        return $this->belongsTo('app\admin\model\mox\inherit\story\Info', 's_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
    public function chapter()
    {
        return $this->belongsTo('app\admin\model\mox\inherit\story\Chapter', 'c_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
    public function videofilename()
    {
        return $this->belongsTo('app\common\model\Attachment', 'video', 'url', [], 'LEFT')->setEagerlyType(0);
    }
}
